package Q398

import java.util.*

class Main {

}

/**
 * @author 23737
 * @time 2022.4.25
 */
fun main() {

}

class Solution(nums: IntArray) {

    var array = nums.clone()
    fun pick(target: Int): Int {
        var count = 0
        for (i in array.indices) {
            if (array[i] == target) {
                count++
            }
        }
        val choose = Random().nextInt(count) + 1
        count = 0
        for(i in array.indices){
            if(array[i] == target){
                count++
                if(count == choose){
                    return i
                }
            }
        }
        return -1
    }
}



/**
 * Your Solution object will be instantiated and called as such:
 * var obj = Solution(nums)
 * var param_1 = obj.pick(target)
 */